//
//  ExchangeRateViewController.m
//  TeamProject_Travel
//
//  Created by lanou3g on 16/4/7.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "ExchangeRateViewController.h"

@interface ExchangeRateViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *CNYTextField;
@property (weak, nonatomic) IBOutlet UITextField *USDTextField;
@property (weak, nonatomic) IBOutlet UITextField *JPYTextField;
@property (weak, nonatomic) IBOutlet UITextField *EURTextField;

@end

@implementation ExchangeRateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.CNYTextField.delegate = self;
    self.USDTextField.delegate = self;
    self.JPYTextField.delegate = self;
    self.EURTextField.delegate = self;
    
    self.CNYTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.USDTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.JPYTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.EURTextField.keyboardType = UIKeyboardTypeNumberPad;
    
    
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
    //设置成NO表示当前控件响应后会传播到其他控件上，默认为YES。
    tapGestureRecognizer.cancelsTouchesInView = NO;
    //将触摸事件添加到当前view
    [self.view addGestureRecognizer:tapGestureRecognizer];
    
}

// 点击空白处回收键盘
-(void)keyboardHide:(UITapGestureRecognizer*)tap{
    [self.CNYTextField resignFirstResponder];
    [self.USDTextField resignFirstResponder];
    [self.JPYTextField resignFirstResponder];
    [self.EURTextField resignFirstResponder];
}

- (IBAction)CNYAction:(UIButton *)sender {
    
    self.USDTextField.text = [NSString stringWithFormat:@"%.2f",0.155 * [self.CNYTextField.text floatValue]];
    self.JPYTextField.text = [NSString stringWithFormat:@"%.2f",16.744 * [self.CNYTextField.text floatValue]];
    self.EURTextField.text = [NSString stringWithFormat:@"%.2f",0.136 * [self.CNYTextField.text floatValue]];
}

- (IBAction)USDAction:(UIButton *)sender {
    self.CNYTextField.text = [NSString stringWithFormat:@"%.2f",6.468 * [self.USDTextField.text floatValue]];
    self.JPYTextField.text = [NSString stringWithFormat:@"%.2f",108.29 * [self.USDTextField.text floatValue]];
    self.EURTextField.text = [NSString stringWithFormat:@"%.2f",0.8818 * [self.USDTextField.text floatValue]];
}

- (IBAction)JPYAction:(UIButton *)sender {
    self.CNYTextField.text = [NSString stringWithFormat:@"%.2f",0.0597 * [self.JPYTextField.text floatValue]];
    self.USDTextField.text = [NSString stringWithFormat:@"%.2f",0.0092 * [self.JPYTextField.text floatValue]];
    self.EURTextField.text = [NSString stringWithFormat:@"%.2f",0.0081 * [self.JPYTextField.text floatValue]];
}

- (IBAction)EURAction:(UIButton *)sender {
    self.CNYTextField.text = [NSString stringWithFormat:@"%.2f",7.3348 * [self.EURTextField.text floatValue]];
    self.USDTextField.text = [NSString stringWithFormat:@"%.2f",1.1341 * [self.EURTextField.text floatValue]];
    self.JPYTextField.text = [NSString stringWithFormat:@"%.2f",122.8117 * [self.EURTextField.text floatValue]];
}

@end
